<template>
  <div>
    <el-card class="box-card" style="margin:20px">
      <div slot="header" class="clearfix">
        <el-form :inline="true">
          <el-form-item label="名称" style="margin-bottom:0px;">
            <el-input v-model="searchName" placeholder="输入名称" />
          </el-form-item>
          <el-form-item style="margin-bottom:0px;">
            <el-button type="primary" icon="el-icon-search" @click="getProjectList">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table v-loading="loading" :data="tableData" style="width: 100%">
        <el-table-column
          prop="businessCode"
          label="业务编码"
          min-width="50%"
        />
        <el-table-column
          prop="itemName"
          label="事项名称"
          min-width="50%"
        />
        <el-table-column
          prop="itemCode"
          label="事项编码"
          min-width="50%"
        />
        <el-table-column
          prop="updateTime"
          label="操作时间"
          min-width="40%"
        />
        <el-table-column
          align="center"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button
              size="medium"
              type="text"
              @click="view(scope.$index, scope.row)"
            >
              查看
            </el-button>
            <el-button
              size="medium"
              type="text"
              @click="approval(scope.$index, scope.row)"
            >
              审批
            </el-button>
            <el-button
              size="medium"
              type="text"
              @click="remove(scope.$index, scope.row)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="float:right;margin:20px">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 0,
      searchName: '',
      loading: false
    }
  },
  mounted() {
    this.getProjectList()
  },
  methods: {
    getProjectList() {
      this.loading = true
      var params = {
        'pageSize': this.pageSize,
        'pageNum': this.currentPage,
        'name': this.searchName
      }
      this.$axios.get(this.baseProjectUrl + '/api/page', {
        params
      }).then(res => {
        this.tableData = res.data.data.records
        this.total = parseInt(res.data.data.total)
        this.loading = false
      }).catch(() => {
        this.loading = false
        this.$message.error('获取办件列表失败')
      })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getProjectList()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getProjectList()
    },
    view(index, row) {
      this.$axios.get(this.basePortalUrl + '/system/getById/' + row.systemId)
        .then(res => {
          const src = res.data.data.applyUrl + '?businessCode=' + row.businessCode + '&itemCode=' + row.itemCode + '&action=view'
          window.open(src, '_black')
        }).catch(() => {
          this.loading = false
          this.$message.error('获取模板列表失败')
        })
    },
    approval(index, row) {
      this.$axios.get(this.basePortalUrl + '/system/getById/' + row.systemId)
        .then(res => {
          const src = res.data.data.applyUrl + '?businessCode=' + row.businessCode + '&itemCode=' + row.itemCode + '&action=approval'
          window.open(src, '_black')
        }).catch(() => {
          this.loading = false
          this.$message.error('获取模板列表失败')
        })
    },
    remove: function(index, row) {
      this.$confirm('删除后业务系统将无法获取改办件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.$axios.delete(this.baseProjectUrl + '/api/business', {
          params: {
            businessId: row.id
          }
        }).then(res => {
          if (res.data.code === 200) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getProjectList()
          } else {
            this.$message({
              type: 'error',
              message: res.data.msg
            })
          }
        }).catch(() => {
          this.$message({
            type: 'error',
            message: '删除失败'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

